package com.example.administrator.printoutindemo;

import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.dds.soap.SoapListener;
import com.dds.soap.SoapParams;
import com.example.administrator.printoutindemo.base.BaseActivity;
import com.example.administrator.printoutindemo.services.Tools;
import com.jess.arms.base.BaseConstants;
import com.jess.arms.utils.ArmsUtils;
import com.xiaoxing.gifloadingview.LoadingDialogUtil;

import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;

import java.util.List;

import me.jessyan.armscomponent.commonres.utils.ToolbarUtils;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;

@Route(path = RouterHub.APP_STORE_OUT_STORAGE_CHECK_LIST_1_ACTIVITY)
public class StoreOutStorageCheckList1Activity extends BaseActivity {

    private static final String WEBSERVICE_CONFIG = "TEXT";
    private static final int LOGINSUCCESS = 0;
    private static final int NETWORKERROR = 2;
    private static final int SYSERROR = 3;
    View mEmptyLayout;
    TextView empty_text;
    ImageView empty_image;
    private ListView store_cl_listView_outStorage = null;
    private OutStorageCheckList outStorageCheckList = null;
    private List<OutStorageCheckList> li_osc = null;
    private StoreOutStorageCheckList1Adapter adapter = null;
    private SharedPreferences sPreferencces;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.store_activity_outstoragechecklist_1);
        ToolbarUtils.initToolbarTitleBack(this, "审核");
        initEmpty();

        sPreferencces = getSharedPreferences(WEBSERVICE_CONFIG, 0);
        store_cl_listView_outStorage = (ListView) findViewById(R.id.store_cl_listView_outStorage);
        outStorageCheckList = new OutStorageCheckList();
        adapter = new StoreOutStorageCheckList1Adapter(this);

//		final int user_id = ((dyjApplication) getApplication()).get_user_id();//审核人ID

    }


    private void initEmpty() {
        mEmptyLayout = (View) findViewById(R.id.empty);
        empty_text = (TextView) findViewById(R.id.empty_text);
        empty_image = (ImageView) findViewById(R.id.empty_image);

        empty_image.setImageResource(com.xiaoxing.zhinenghuacangku.R.drawable.ic_empty);
        empty_text.setTextColor(Color.parseColor("#CFCFCF"));
        empty_text.setText("暂无数据");
    }


    @Override
    protected void onResume() {
        super.onResume();
        getShenHeData();
    }

    private void getShenHeData() {
        int user_id = Integer.parseInt(sPreferencces.getString(BaseConstants.UID, ""));//审核人ID
        if (user_id != 0) {
            getCheckProject(String.valueOf(user_id));

        } else {
            Tools.showDialogInfo(this, "登录已过期，请重新登录");
        }
    }

    private void getCheckProject(String user_id) {

        LoadingDialogUtil.showGifdialog2(getSupportFragmentManager(), R.drawable.public_loading);


        String methodName = "GetCheckProject";

        SoapParams params = new SoapParams();
        params.put("user_id", user_id);

        /**
         * 请求
         */
        soapUtil.callEntry(getUrl(), BaseConstants.NAME_SPACE, methodName, params, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {
                LoadingDialogUtil.dismissDialog();

                String result = object.getProperty(methodName + "Result").toString();
                if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100")) {
                    if (li_osc != null) li_osc.clear();
                    li_osc = outStorageCheckList.getListFromJSON(result);

                    if (li_osc != null && li_osc.size() > 0) {

                        adapter.setList(li_osc);
                        store_cl_listView_outStorage.setAdapter(adapter);

                        mEmptyLayout.setVisibility(View.GONE);
                        store_cl_listView_outStorage.setVisibility(View.VISIBLE);

                    } else {
                        mEmptyLayout.setVisibility(View.VISIBLE);
                        store_cl_listView_outStorage.setVisibility(View.GONE);

                    }
                } else {
                    mEmptyLayout.setVisibility(View.VISIBLE);
                    store_cl_listView_outStorage.setVisibility(View.GONE);
                }

            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
                LoadingDialogUtil.dismissDialog();
                ArmsUtils.makeText(getContext(), error.getMessage());

            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
                LoadingDialogUtil.dismissDialog();

            }
        }, getAapiUserName(), getApiPwd());

    }
}